<!--
 * @Author: ૮₍ ˙О˙₎ა
 * @Date: 2023-07-12 18:19:45
-->
<template>
  <div class="home">
    <div class="content" ref="content">
      <header class="top">
        <div class="headerLeft">
          <a href="" class="news">新闻管理</a>
        </div>
        <div class="headerCenter">尚品汇后台可视化数据展示</div>
        <div class="headerRight">
          <a href="" class="headerRight-left">地图管理</a>
          <span class="headerRight-Right">当前时间:{{ date }}</span>
        </div>
      </header>
      <main class="main">
        <TopView></TopView>
        <MiddleView></MiddleView>
        <BottomView></BottomView>
      </main>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { useUserInfoStore } from '@/stores/userInfo'
import { onMounted, ref } from 'vue'
import moment from 'moment'
import TopView from './components/TopView/index.vue'
import MiddleView from './components/MiddleView/index.vue'
import BottomView from './components/BottomView/index.vue'
import { useEchartsStore } from '@/stores/echarts'
const echartsStore = useEchartsStore()

const date = ref()
const getDate = () => {
  date.value = moment().format('YYYY年MM月DD日 HH时mm分ss秒')
}

onMounted(() => {
  getDate()
  setInterval(() => {
    getDate()
  }, 1000)

  const socket = new WebSocket('ws://localhost:8000')
  socket.onmessage = (event) => {
    const data = JSON.parse(event.data)
    echartsStore.getEchartsData(data)
  }
  resize()
  window.onresize = resize
})

const content = ref()
const resize = () => {
  let dw = document.documentElement.clientWidth
  let dh = document.documentElement.clientHeight

  let tw = 1920
  let th = 780.6
  const scale = dw / tw > dh / th ? dh / th : dw / tw
  content.value.style.transform = `scale(${scale}) translate(-50%, -50%)`
}
</script>

<script lang="ts">
export default {
  name: 'HomeView',
}
</script>

<style lang="scss" scoped>
@mixin setImg {
  background-repeat: no-repeat;
  background-size: contain;
}

.home {
  width: 100%;
  height: 100%;
  background-image: url(./images/bg.png);
  background-repeat: no-repeat;
  background-size: cover;
  overflow: hidden;
  position: relative;
  .content {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    transform-origin: top left;
    .top {
      display: flex;
      height: 40px;
      color: aqua;
      text-align: center;
      .headerLeft {
        flex: 1;
        background-image: url(./images/dataScreen-header-left-bg.png);
        @include setImg;
        position: relative;
        .news {
          position: absolute;
          right: 0;
          top: 0;
          background-image: url(./images/dataScreen-header-btn-bg-l.png);
          @include setImg;
          width: 100px;
          height: 40px;
          font-size: 14px;
          line-height: 30px;
        }
      }
      .headerCenter {
        flex: 1;
        @include setImg;
        background-image: url(./images/dataScreen-header-center-bg.png);
        font-size: 20px;
        font-weight: bold;
        line-height: 40px;
      }
      .headerRight {
        flex: 1;
        @include setImg;
        display: flex;
        justify-content: space-between;
        background-image: url(./images/dataScreen-header-right-bg.png);
        .headerRight-left {
          background-image: url(./images/dataScreen-header-btn-bg-r.png);
          @include setImg;
          width: 100px;
          height: 40px;
          font-size: 14px;
          line-height: 30px;
        }
        .headerRight-Right {
          padding-right: 8px;
          font-size: 12px;
          line-height: 30px;
        }
      }
    }
  }
}
</style>
